<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="https://www.thymeleaf.org">
<head>
    <title>员工管理</title>
    <meta charset="utf-8" name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" type="text/css" media="all" href="/css/bootstrap.css">
    <link rel="stylesheet" type="text/css" media="all" href="/layui/css/layui.css">
    <script type="text/javascript" src="/js/jquery-3.6.0.js"></script>
    <script type="text/javascript" src="/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="/layui/layui.js"></script>
</head>
<script>
    function updateValues(ID){
        $("#UpdateID").val(ID);
    }
    function deleteValues(ID){
        $("#DeleteID").val(ID);
    }
    function SearchEmployee() {
        var employeeInfo = $("#employeeSearch").val();
        data = {
            employeeInfo: employeeInfo
        }
        $.ajax({
            url:"/employeeSearch",
            type: "Post",
            data: data,
            datatype: "html",
            success: function (data, status) {
                $("#roomInformation").replaceWith(data);
            }
        })
    }
    function AddEmployee(){
        var name = $("#AddName").val();
        var sex = $("#AddSex").val();
        var birthday = $("#AddBirthday").val();
        var phone = $("#AddPhone").val();
        var job = $("#AddJob").val();
        data = {
            name: name,
            sex: sex,
            birthday: birthday,
            phone: phone,
            job: job
        }
        $.ajax({
            url:"/admin/insertEmployee",
            type: "Post",
            data:data,
            datatype: "html",
            success: function(data, status) {
                $("#roomInformation").replaceWith(data);
            }
        })
        setTimeout(function () {
            location.reload();
        }, 3000);
    }
    function UpdateEmployee(){
        var employeeID = $("#UpdateID").val();
        var job = $("#UpdateJob").val();
        data = {
            employeeID: employeeID,
            job: job
        }
        $.ajax({
            url:"/admin/updateEmployeeJob",
            type: "Post",
            data:data,
            datatype: "html",
            success: function(data, status) {
                $("#roomInformation").replaceWith(data);
            }
        })
        setTimeout(function () {
            location.reload();
        }, 3000);
    }

    function DeleteEmployee(ID){
        var employeeID = $("#DeleteID").val();
        data = {
            employeeID: employeeID
        }
        $.ajax({
            url:"/admin/deleteEmployee",
            type: "Post",
            data:data,
            datatype: "html",
            success: function(data, status) {
                $("#roomInformation").replaceWith(data);
            }
        })
        setTimeout(function () {
            location.reload();
        }, 3000);
    }
</script>
<body>
<div class="container mt-3" id="roomInformation">
    <h2>员工管理界面</h2>
    <br>
    <form class="form-inline" action="/selectAllEmployee" method="post">
    </form>
    <ul class="nav nav-pills" role="tablist">
        <li class="navbar-form navbar-left" role="search">
            <a class="form-group">
                <input type="text" class="form-control" id="employeeSearch" placeholder="搜索相关员工"/>
            </a>
        </li>
        <li><button type="submit" class="btn btn-default" onclick="SearchEmployee()">搜索</button></li>
        <li class="pagination"><button type="button" class="btn btn-light btn-sm" data-bs-toggle="modal" data-bs-target="#add">添加员工</button></li>
    </ul>

    <div class="tab-content">
        <div id="home" class="container tab-pane active"><br>
            <table class="table table-bordered">
                <thead>
                <tr>
                    <th>员工号</th>
                    <th>姓名</th>
                    <th>性别</th>
                    <th>出生日期</th>
                    <th>联系方式</th>
                    <th>职位</th>
                    <th>工作状态</th>
                    <th>修改</th>
                    <th>删除</th>
                </tr>
                </thead>
                <tbody>
                <tr th:each="employee:${employees}">
                    <td th:text="${employee.employeeID}"></td>
                    <td th:text="${employee.name}"></td>
                    <td th:if="${employee.sex}==1">男</td>
                    <td th:if="${employee.sex}==0">女</td>
                    <td th:text="${employee.birthday}"></td>
                    <td th:text="${employee.phone}"></td>
                    <td th:text="${employee.job}"></td>
                    <td th:if="${#strings.contains(employee.state, '000')}">不在店内</td>
                    <td th:if="${#strings.contains(employee.state, '001')}">在店内</td>
                    <td th:if="!${#strings.contains(employee.state, '000')} and !${#strings.contains(employee.state, '001')}" th:text="'在' + ${employee.state} + '房'"></td>
                    <td><button type="button" class="btn btn-light btn-sm" data-bs-toggle="modal" data-bs-target="#modify" th:onclick="|javascript:updateValues('${employee.employeeID}')|">修改</button></td>
                    <td><button type="button" class="btn btn-light btn-sm" data-bs-toggle="modal" data-bs-target="#fire" th:onclick="|javascript:deleteValues('${employee.employeeID}')|">删除</button></td>
                </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>

<div class="modal alter" id="modify">
    <div class="modal-dialog modal-lg">
        <div class="modal-content" style="width:650px">

            <div class="modal-header">
                <h3 class="modal-title">员工信息</h3>
                <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
            </div>

            <div class="modal-body">
                <table class="table table-bordered">
                    <thead>
                    </thead>
                    <tbody>
                    <tr>
                        <td style="font-size:22px">员工号</td><td><input readonly="readonly" id="UpdateID" name="UpdateID" style="height:32px;width:300px;font-size:22px"></td>
                    </tr>
                    <tr>
                        <td style="font-size:22px">职位</td><td><input id="UpdateJob" name="UpdateJob" style="height:32px;width:300px;font-size:22px"></td>
                    </tr>
                    </tbody>
                </table>
            </div>

            <div class="modal-footer">
                <button type="button" class="btn btn-danger" data-bs-dismiss="modal" onclick="UpdateEmployee()">确定</button>
            </div>

        </div>
    </div>
</div>
<div class="modal Add" id="add">
    <div class="modal-dialog modal-lg">
        <div class="modal-content" style="width:650px">

            <div class="modal-header">
                <h3 class="modal-title">员工信息</h3>
                <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
            </div>

            <div class="modal-body">
                <table class="table table-borderless">
                    <tr>
                        <td style="font-size:22px">姓名</td><td><input id="AddName" name="AddName" placeholder="请输入姓名" style="height:32px;width:300px;font-size:22px"></td>
                    </tr>
                    <tr>
                        <td style="font-size:22px">性别</td>
                        <td>
                            <select id="AddSex" name="AddSex" style="height:32px;font-size:18px" type="button" class="btn btn-light btn-sm">
                                <option value="1">男</option>
                                <option value="0">女</option>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td style="font-size:22px">出生日期</td><td><input id="AddBirthday" name="AddBirthday" type="date" placeholder="请选择出生日期" style="height:32px;width:300px;font-size:22px"></td>
                    </tr>
                    <tr>
                        <td style="font-size:22px">联系方式</td><td><input id="AddPhone" name="AddPhone" placeholder="请输入联系方式" style="height:32px;width:300px;font-size:22px"></td>
                    </tr>
                    <tr>
                        <td style="font-size:22px">职位</td><td><input id="AddJob" name="AddJob" placeholder="请输入职位" style="height:32px;width:300px;font-size:22px"></td>
                    </tr>
                </table>
            </div>

            <div class="modal-footer">
                <button type="button" class="btn btn-danger" data-bs-dismiss="modal" onclick="AddEmployee()">确定</button>
            </div>

        </div>
    </div>
</div>
<div class="modal Fire" id="fire">
    <div class="modal-dialog modal-lg">
        <div class="modal-content" style="width:650px">

            <div class="modal-header">
                <h3 class="modal-title">删除员工</h3>
                <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
            </div>

            <div class="modal-body">
                <table class="table table-bordered">
                    <thead>
                    </thead>
                    <tbody>
                    <tr>
                        <td style="font-size:22px">员工号</td><td><input readonly="readonly" id="DeleteID" name="DeleteID" style="height:32px;width:300px;font-size:22px"></td>
                    </tr>
                    <tr>
                        <td style="font-size:22px">是否删除该员工？</td><td style="height:32px;width:300px;font-size:22px">永久删除该员工（真的很久）</td>
                    </tr>
                    </tbody>
                </table>
            </div>

            <div class="modal-footer">
                <button type="button" class="btn btn-danger" data-bs-dismiss="modal" onclick="DeleteEmployee()">是</button>
            </div>

        </div>
    </div>
</div>
</body>
</html>